<!DOCTYPE html>
<html  lang="zh-CN">
<head>
  <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
  <meta content=always name=referrer>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta name="format-detection" content="telephone=no"/>
  <meta name="keywords" content=""/>
  <meta name="description" content=""/>
  <title>确认订单</title>
  <link rel="stylesheet" type="text/css" href="__STATIC__/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="__STATIC__/css/swiper.min.css">
  <link rel="stylesheet" type="text/css" href="__STATIC__/css/public.css">
  <link rel="stylesheet" type="text/css" href="__STATIC__/css/base.css">
  <script src="__STATIC__/js/jquery-1.11.3.min.js"></script>
  <script src="__STATIC__/js/jquery.form.min.js"></script>
  <script src="__STATIC__/layer/layer.js"></script>
  <script src="__STATIC__/js/Validform_v5.3.2_min.js"></script>
  <script src="__STATIC__/js/Validform_Datatype.js"></script>
  <script src="__STATIC__/js/bootstrap.min.js"></script>
  <script src="__STATIC__/dialog/js/mh_dialog.js"></script>
  <script>
    $(function () {
      $(".header .menu>div .list li").click(
          function () {
            $(this).addClass("active").siblings().removeClass("active");
          }
      )
      $(".header .menu>div .type").mouseover(
          function () {
            $(this).find(".menu-group").css({display:"block"});
          }
      )
      $(".header .menu>div .type>div").mouseout(
          function () {
            $(this).css({display:"none"});
          }
      )
      $(".coupon_use").click(
          function () {
            $(this).toggleClass("coupon_more");
            $(this).next(".coupon_det").toggleClass("show");
          }
      )
    })
  </script>
</head>
<body>
<div class="wrap">
  <div class="header">
    <div class="header-login">
      <div class="menu-bar">
        <div>欢迎来到{:cache('web_name')}，{if condition="session('member_id')"}尊敬的：{:session('member_name')}<a href="{:url('login/logout')}" class="register"> 注销登录 </a>{else/}<a href="{:url('login/index')}" class="login"> 请登录 </a> <a href="#" class="register"> 免费注册 </a>{/if}</div>
        <ul>
          <li><a href="#"><span>客服服务</span></a></li>
          {if condition="session('member_id')"}
          <li><a href="{:url('shop/memberOrder/index')}"><span>我的订单</span></a></li>
          {else/}
          <li><a href="{:url('shop/login/index')}"><span>我的订单</span></a></li>
          {/if}
          <li class="collect"><a href="#"><span>我的收藏</span></a></li>
          <!--<li><a href="#"><img src="__STATIC__/img/icon1.png" class="icon"><span>手机红树湾</span></a></li>-->
        <!--</ul>-->
      </div>
    </div>
    <div class="logo logo_cart">
      <img src="__STATIC__/img/logo_ishop.png" class="logo-icon">
      <table class="process right" border="0">
        <tr>
          <td class="text-center">
            <div class="num">1</div>
            <div class="title">1.我的购物车</div>
          </td>
          <td class="text-center">
            <div class="num">2</div>
            <div class="title">2.填写核对订单信息</div>
          </td>
          <td class="text-center step">
            <div class="num">3</div>
            <div class="title">3.成功提交订单</div>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <form method="post" id="set_form">
  <div class="content_order" style="min-height: 900px;">
    <h4>填写并核对订单信息</h4>
    <div class="order_info">
      <div class="order_det">
        <div class="order_title"><span>收货人信息</span><a href="javascript:add_address();" class="right">新增收货地址</a></div>
        <div class="det">
          {if condition="$address"}
         <span class="active_address" style="white-space: pre-wrap;width: 858px;">{$address.name}  {$address.area_info}  {$address.address}     {$address.phone}</span>
          <a href="javascript:other_address();" class="right" style="font-size: 14px;color: #E73F09;line-height: 30px;">更多收货地址</a>
          {else/}
          {notempty name="address_list"}
          <a onclick="other_address();">
            <a href="javascript:other_address();" class="right" style="font-size: 12px;color: #E73F09;line-height: 30px;">去选择收货地址</a>
          </a>
          {/notempty}
          {/if}
        </div>
      </div>

      <div id="dizhi" style="display: none;">
        <table border="0" style="margin-left: 20px;">
          <tr>
            <td class="name text-center" style="width: 80px;">收货人</td>
            <td class="area text-center" style="width: 200px;">所在地区</td>
            <td class="address text-center" style="width: 400px;">详细地址</td>
            <td class="phone text-center" style="width: 100px;">电话/手机</td>
            <td class="operate text-center" style="width: 120px;">操作</td>
          </tr>
          {volist name="address_list" id="vo"}
          <tr>
            <td class="name text-center" style="text-align:center">{$vo.name}</td>
            <td class="area text-left" style="text-align:left;"><div style="white-space: nowrap;text-overflow: ellipsis;overflow: hidden;width: 200px;">{$vo.area_info}</div></td>
            <td class="address text-center" style="text-align:left;"><div  style="white-space: nowrap;text-overflow: ellipsis;overflow: hidden;width: 400px;">{$vo.address}</div></td>
            <td class="phone text-center" style="text-align:center">{$vo.phone}</td>
            <td class="primary text-center"><span><a href="javascript:chose_address({$vo.id});" style="color: black;">选择该地址</a></span></td>
          </tr>
          {/volist}
        </table>
      </div>

      <div class="order_det">
        <div class="order_title"><span>支付方式</span></div>
        <div class="method">
          <div class="active">在线支付</div>
        </div>
      </div>

      <div class="order_det">
        <div class="order_title"><span>送货清单</span><a href="{:url('ShopCart/index')}" class="right">返回修改购物车</a></div>
        <!--<div class="order_list">-->
        <div class="delivery">
          <div class="delivery_det">配送方式</div>
          <div class="active">快递运输</div>
          <div class="delivery_det"><span>配送时间：</span>工作日，双休日与节假日均可送货</div>
        </div>
        <!--店铺-->
        {volist name="data" id="item" key="k"}

        <div class="shop_det">
          <div class="delivery_det">商家：{$key}</div>

          {volist name="item.data" id="vo"}
          <!--商品-->
          <ul class="list">
            <li class="goods">
              <a href="#">
                <div class="goods_det">
                  <img src="/{$vo.shopGoods.thumb_img}" class="left">
                  <div class="right">
                    <div class="name">{$vo.shopGoods.title}</div>
                    <!--<div class="tips">支持7天无理由退货</div>-->
                  </div>
                </div>
              </a>
            </li>
            <li class="price text-center">￥{$vo.price}</li>
            <li class="total text-center">{empty name="$vo.attr"}无属性{else/}{$vo.attr}{/empty}</li>
            <li class="num text-center">×{$vo.number}</li>
            <li class="total text-center">有货</li>
          </ul>
          <!--商品-->
          {/volist}
        </div>
        <!--备注-->
        <div class="add_remark">
          <span>添加订单备注</span>
          <div>
            <input type="text" name="message[]" placeholder="限45个字（定制类商品，请将购买需求在备注中做详细说明）">
            <label>提示：请勿填写有关支付，收货，发票方面的信息</label>
          </div>
        </div>
        <!--备注-->
        {empty name="combo_has"}
        <!--优惠券-->
        <div class="coupon">
          <div class="coupon_use">使用优惠券 <img src="__STATIC__/img/more3.png"></div>
          <div class="coupon_det">
            <div class="coupon_classify"><span>优惠券</span></div>

            <div class="list-coupon">
              <input type="hidden" name="coupon_id" value="{$item.coupon_id}">
              {volist name="$item['coupon']" id="vs"}
              <ul class="not_used" style="float: left;">
                <li onclick="use_coupon({$vs.id},{$k})">
                  <div class="price">￥{$vs.actual_price}<span>满{$vs.virtual_price}</span></div>
                  <div class="time">有效期至{:date('Y-m-d H:i:s',$vs.end_time)}</div>
                  <div class="use">[消费满{$vs.virtual_price}元使用]</div>
                </li>
              </ul>
              {/volist}
            </div>
          </div>
        </div>
        <!--优惠券-->
        {/empty}
        <!--店铺-->
        <div class="total_num">
          <table border="0">
            <tr>
              <td><span>{$item.shop_number} </span>件商品，总商品金额：</td>
              <td>￥<span id="total_goods{$k}">{$item.shop_price}</span></td>
            </tr>
            <tr>
              <td>运费：</td>
              <td>
                <img src="__STATIC__/img/icon64.png">￥{$item.shop_freight}
                <input id="total_{$k}" hidden value="{$item.shop_price+$item.shop_freight}">
                <input type="hidden" id="shop_total_{$k}" value="{$item.shop_price+$item.shop_freight}"/>
                <input type="hidden" name="total_price[]" value="{$item.shop_price+$item.shop_freight}"/>
              </td>
            </tr>
          </table>
        </div>

        <!--</div>-->
        {/volist}


      </div>
    </div>
    {empty name="combo_has"}
    <div class="coupon">
      <div class="coupon_use" style="margin-left: 20px;">红包抵用 <img src="__STATIC__/img/more3.png"></div>
      <div class="coupon_det">
        <div class="coupon_classify"><span>红包</span></div>

        <div class="list-coupon">
          <input type="hidden" name="red_packet_id" value="">
          {volist name="$item['red_packet']" id="vs"}
          <ul class="not_used">
            <li onclick="use_packet({$vs.id})">
              <div class="price">￥{$vs.actual_price}<span>满{$vs.virtual_price}</span></div>
              <div class="time">有效期至{:date('Y-m-d H:i:s',$vs.end_time)}</div>
              <div class="use">[消费满{$vs.virtual_price}元使用]</div>
            </li>
          </ul>
          {/volist}
        </div>
      </div>
    </div>
    {/empty}
    <div class="total_num">
      <div>
        <table border="0">
          <tr>
            <input type="hidden" id="cart" value="{$cart_id}">
            <input type="hidden" name="zongjia" value="{$total.total_price}"/>
            <input type="hidden" name="trimData" value="{$trimData}"/>
            <input type="hidden" name="address_id" value="{$address.id}" id="address_id">
            <td><span>{$total['total_number']}</span>件商品，总商品金额：</td>
            <td class="price">￥<font id="prices">{$total.total_price}</font></td>
          </tr>
        </table>
        <div class="det_add text-right right">寄送至：{$address.area_info}{$address.address}{$address.name}{$address.phone}</div>
      </div>
      <input type="button" value="提交订单" onclick="putData()" class="submit_order right" >
    </div>
  </div>
</form>
</div>
</body>
<script>

  // 使用优惠券
  function use_coupon(coupon_id,shop_key) {
    // 获取店铺金额小计
    var price = parseInt($('#shop_total_' + shop_key).val());
    // 获取input标签位置
    var serial_number = shop_key-1;

    if (coupon_id == 0) {
      // 优惠卷隐藏余赋值
      $(":hidden[name='coupon_id']").eq(serial_number).val(0);
      return false;
    }

    // 调用ajax
    $.ajax({
      url: "{:url('shop/coupon/user_coupon')}",
      type: 'post',
      dataType: 'json',
      data: {'coupon_id': coupon_id, 'price': price},
      // 回调函数
      success:function (data) {
        if (data.code==200) {
          // 优惠卷隐藏余赋值
          $(":hidden[name='coupon_id']").eq(serial_number).val(coupon_id);
          // 调用刷新网页函数
          comfirm_reload();
        }else {
          layer.msg(data.message);
        }
      }

    });
  }

  // 添加地址
  function add_address() {
    layer.open({
      type: 2,
      area: ['700px', '530px'],
      fixed: false, //不固定
      maxmin: true,
      content: "{:url('shop/address/account_address')}"
    });

  }

  // 更多地址
  function other_address() {
    $('#dizhi').toggle();

  }

  // 选择地址
  function chose_address(select_address_id) {

    // 地址隐藏余赋值
    $('#address_id').val(select_address_id);

    // 调用刷新网页函数
    comfirm_reload();
  }


  // 使用红包
  function use_packet() {
    // 获取选择的红包ID
    var red_paceket_id = $("#red_packet").val();

    // 订单总价格
    var consult = $("#zong_jia").val();

    // 调用ajax
    $.ajax({
      url: "{:url('shop/coupon/user_red_packet')}",
      type: 'post',
      data: {'red_id': red_paceket_id, 'price': consult},
      success:function (data) {
        if (data.code == 200) {
          // 红包ID隐藏余赋值
          $('#red_packet_id').val(red_paceket_id);
          // 调用刷新网页函数
          comfirm_reload();
        }else {
          layer.msg(data.message);
        }
      }

    })
  }

  // 刷新页面函数
  function comfirm_reload() {
    // 获取购物车ID
    var cart_id = $('#cart').val();
    //  获取地址ID
    var address = $('#address_id').val();
    // 获取红包ID
    var red_packet = $("#red_packet").val();
    // 优惠卷ID
    var coupon_id = '';
    $(":hidden[name='coupon_id']").each(function(i,n){
      coupon_id+= n.value+',';
    });
    coupon_id=coupon_id.substring(0,coupon_id.length-1);
    if ("{:input('act')}" == "temporary") {
      var url = "{:url('shop/shop_cart/confirm_order')}?act=temporary&cart_id="+cart_id+"&address_id="+address+"&coupon_id="+coupon_id+"&red_packet_id="+red_packet+"#miao";
    }else {
      var url = "{:url('shop/shop_cart/confirm_order')}?cart_id="+cart_id+"&address_id="+address+"&coupon_id="+coupon_id+"&red_packet_id="+red_packet+"#miao";
    }


    window.location.href= url;
  }

  //表单提交
  function putData() {
    // 订单总价
    var zong_jia = $('#zongjia').val();

    if (zong_jia<0) {
      layer.msg('金额不能为负数！');
    }
    $('#set_form').ajaxSubmit({
      url: "{:url('shop/shop_cart/commit_order')}",
      type: 'post',
      dataType: 'json',
      success: function (t) {
        if (t.code == 200) {
          setTimeout(function () {
            //跳转到选择支付类型页面
            window.location.href = "{:url('shop/payment/index')}?order_number=" + t.oid;
          }, 1000);
        } else {

          layer.msg(t.message);

        }
      }
    })
  }

</script>
</html>